package com.s05.homework.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class User {

	private String name;
	private String surname;
	private String dob;
	private Long created;
	private Long updated;
	private Integer age;

	public void setUser(String userdata) {
		name = userdata.split(",")[0];
		surname = userdata.split(",")[1];
		dob = userdata.split(",")[2];
	}

	public void creatAccount() {
		Date now_created = new Date();
		created = now_created.getTime();
		System.out.println("Hey " + name.toUpperCase() + " "
				+ surname.toUpperCase() + "\nYour account has been created: "
				+ now_created);
	}

	public void updateAccount() {
		Date now_updated = new Date();
		updated = now_updated.getTime();
		System.out.println("Your account has been updated: " + now_updated);
		System.out.println("It took as little as " + (updated - created)
				+ " ms since the account has been created ");
	}

	public void parseAge() {

		try {
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
			Date date_dob = dateFormat.parse(dob);

			Calendar dob = Calendar.getInstance();
			dob.setTime(date_dob);
			Calendar today = Calendar.getInstance();
			age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);

			System.out.println("You are " + age + " old.");

		} catch (ParseException e) {
			System.out.println("Error encountered: " + e.toString());
			System.exit(1);

		}
	}
}
